﻿/// <copyright file="Default.ascx.cs" company="NotAClue? Studios">
/// Copyright (c) 2011 All Right Reserved, http://csharpbits.notaclue.net/
///
/// This source is subject to the per project license unless otherwise agreed.
/// All other rights reserved.
///
/// </copyright>
/// <author>Stephen J Naughton</author>
/// <email>steve@notaclue.net</email>
/// <project>BMSModule</project>
/// <date>25/07/2011</date>
using System;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace DD_Extensions
{
    public partial class NewDefaultEntityTemplate : System.Web.DynamicData.EntityTemplateUserControl
    {
        protected override void OnLoad(EventArgs e)
        {
            // get a list of groups ordered by group name
            var columns = Table.GetScaffoldColumns(Mode, ContainerType);

            // add table for each group
            foreach (var column in columns)
            {
                var tableRow = new HtmlTableRow();
                tableRow.Attributes.Add("class", "td");

                this.Controls.Add(tableRow);

                var tdHeader = new HtmlTableCell();
                tdHeader.Attributes.Add("class", "DDLightHeader");
                tdHeader.InnerText = column.DisplayName;

                // add header cell to row
                tableRow.Controls.Add(tdHeader);

                var tdData = new HtmlTableCell();
                var dynamicControl = new DynamicControl(Mode)
                {
                    DataField = column.Name,
                    ValidationGroup = this.ValidationGroup
                };
                tdData.Controls.Add(dynamicControl);

                // add data cell to row
                tableRow.Controls.Add(tdData);
            }
        }

        //protected void Label_PreRender(object sender, EventArgs e)
        //{
        //    Label label = (Label)sender;
        //    DynamicControl dynamicControl = (DynamicControl)label.FindControl("DynamicControl");
        //    FieldTemplateUserControl ftuc = dynamicControl.FieldTemplate as FieldTemplateUserControl;

        //    if (ftuc != null && ftuc.DataControl != null)
        //        label.AssociatedControlID = ftuc.DataControl.GetUniqueIDRelativeTo(label);
        //}

        public class _NamingContainer : Control, INamingContainer { }
    }
}